library(clusterProfiler)
library(org.Hs.eg.db)
library(enrichplot)
library(biomaRt)
# 加载R数据
setwd("D:\\RLocal\\Class6")
load("volcano.Rdata")
# 筛选p<0.05的蛋白
prot <- prostat$ID[prostat$P < 0.05 & !is.na(prostat$P)]
# 提取总id
allID <- prostat$ID[!is.na(prostat$P)]
gene.df <- bitr(prot, fromType = "SYMBOL",
                toType = "ENTREZID",
                OrgDb = org.Hs.eg.db)

all.df <- bitr(allID, fromType = "SYMBOL",
               toType = "ENTREZID",
               OrgDb = org.Hs.eg.db)

# 富集分析
ego <- enrichGO(gene = gene.df$ENTREZID,
                universe = all.df$ENTREZID,
                OrgDb = org.Hs.eg.db,
                keyType = "ENTREZID",
                ont = "ALL",
                pvalueCutoff = 0.8,
                qvalueCutoff  = 1,
                minGSSize = 1,
                maxGSSize = 1000,
                readable = TRUE)

# GO富集气泡图绘制
dotplot(ego, showCategory = 15, font.size = 9, title = "GO富集气泡图")
